<?php


namespace App\Http\Controllers\Mini\Shop;

use App\Http\Controllers\Controller;
use App\Services\FullReductionService;
use App\Services\GoodsService;
use App\Services\OrderCommentService;
use App\Services\StoreService;
use Illuminate\Http\Request;


/**
 * 商品接口
 * Class GoodsController
 * @package App\Http\Controllers\Mini
 */
class GoodsController extends Controller
{
    public $goodsModel;

    public function __construct()
    {
        $this->goodsModel = new GoodsService();
    }


    /**
     * @return array
     */
    public function getGoodsList()
    {
        return $this->goodsModel->goodsSearch();
    }


    /**
     * @param Request $request
     * @goods_id
     */
    public function getGoodsInfo(Request $request, GoodsService $goods_service, StoreService $store_service, FullReductionService $full_reduction_service)
    {
        $goods_info = $this->goodsModel->getGoodsInfo($request->goods_id);
        if ($goods_info['status'] === false) {
            return $this->error($goods_info['msg']);
        }
        $goods_info['data']['store_info'] = $store_service->getStoreInfoAndRate($goods_info['data']['store_id'], 'id,store_name,store_company_name,area_info,store_address,after_sale_service')['data'];
        $goods_info['data']['sale_list'] = $goods_service->getSaleSortGoods(['class_id' => $goods_info['data']['class_id']])['data'];   // 销售排名
        $goods_info['data']['full_reductions'] = $full_reduction_service->getFullReductionByStoreId($goods_info['data']['store_id'])['data']; // 满减
        return $this->format($goods_info['data']);

    }


    /**
     * 2021/3/12--18:14
     * @param OrderCommentService $ocs
     * @param $id
     * @return array
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:goods_comment_statistics
     * @effect:评论统计
     */
    public function goods_comment_statistics(OrderCommentService $ocs)
    {
        $id = request()->id;
        $data = $ocs->getCommentStatistics($id);
        if ($data['status']) {
            $data = $ocs->getCommentStatistics($id);
            return $this->format($data['data']);
        }
        return $this->format_error($data['msg']);
    }

    /**
     * 2021/3/12--18:11
     * @param is_type  1=好评 2=中评 3=差评
     * @param OrderCommentService $ocs
     * @param $id
     * @return array
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:goods_comments
     * @effect:获取评论列表
     */
    public function goods_comments(OrderCommentService $ocs)
    {
        $id = request()->id;
        $data = $ocs->getList($id);
        if ($data['status']) {
            $data = $ocs->getList($id);
            return $this->format($data['data']);
        }
        return $this->format_error($data['msg']);
    }
}
